const express=require('express')
const app=express()
const mysql=require('mysql')
const db=mysql.createPool({
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: '123456',
  database: "shopdb"
})
//1.增
app.get('/one',(req,res)=>{
  let sql="insert into t_goods(id,title,imagePath,price) values('5','vivo s15','null','null','2999')"
  db.query(sql,[],(err,result)=>{
    res.send(result)
  })
})
//2.删
app.get('/two',(req,res)=>{
  let sql="delete from t_goods where id=?"
  db.query(sql,[1],(err,result)=>{
    res.send(result)
  })
})
//改
app.get('/three',(req,res)=>{
  let sql="update t_goods set price=3999 where id=?"
  db.query(sql,[2],(err,result)=>{
    res.send(err)
  })
})
//查
app.get('/four',(req,res)=>{
  let sql="select * from t_goods"
  db.query(sql,[],(err,result)=>{
    res.send(result)
  })
})
app.listen(3001,()=>{
  console.log('server is running at port 3001');
})